package gameStates.network;

import com.jme.math.Vector3f;

import networking.messages.syncMessages.NodeSyncMessage;
import networking.messages.syncMessages.ValueType;
import gameStates.absGamesStates.network.AbsServerState;
import logic.ships.hunter.Hunter;
import logic.status.StatusChangedEvent;
import logic.status.StatusListener;

public class TargetSpeedListener implements StatusListener {
	
	private AbsServerState serverState;
	private Hunter target;
	private short playerId;
	
	public TargetSpeedListener(AbsServerState serverState, Hunter target, short playerId) {
		this.serverState = serverState;
		this.target = target;
		this.playerId = playerId;
	}
	
	public void setTarget(Hunter target) { this.target = target; }
	
	@Override
	public void valueChanged(StatusChangedEvent event) {
		if(event.getType() == ValueType.Speed) {
			int objectID = target.getID();
			ValueType type = ValueType.Speed;
			Vector3f loc = target.getLocalTranslation();
			NodeSyncMessage nsm = new NodeSyncMessage(objectID, event.getValue(), type, loc);
			serverState.sendMessageTo(nsm, playerId);
		}
	}
}